package com.xiaoban.controller;


import com.xiaoban.pojo.Users;
import com.xiaoban.service.impl.UsersServiceImpl;
import com.xiaoban.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Title: LoginAndCheck
 * @Author @小班哥
 * @Package com.xiaoban.controller
 * @Date 2024/3/11 21:57
 * @description: 请描述一下这个类是干嘛的
 */
@RestController
@RequestMapping("/user")
public class LoginAndCheck {

    @Autowired
    private UsersServiceImpl usersService;

//    @PreAuthorize("hasAnyAuthority({'system:dept:list' , 'admin' , 'test'})")
    @PreAuthorize("@ex.hasAuthority('system:dept:list')")
    @GetMapping("/hello")
    public String hello() {
        return "Hello, World!";
    }

    @PreAuthorize("@ex.hasAuthority('system:test:list')")
    @GetMapping("/test")
    public String test() {
        return "Hello, World!";
    }


    /**
     * 单点登录接口
     * @param users 用户输入的表单信息
     * @return 返回登录信息
     */
    @ResponseBody
    @PostMapping(path = "/login")
    public ResponseResult login(@RequestBody Users users){
        return usersService.Login(users);
    }

    @ResponseBody
    @GetMapping(path = "/logout")
    public ResponseResult logout(HttpServletRequest request, HttpServletResponse response){
        return usersService.logout(request, response);
    }
}
